package com.base.cn.platform.os;

import com.thetransactioncompany.cors.CORSFilter;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * 前台中心主类
 *
 */
@EnableScheduling
@EnableFeignClients //启用Feign
@EnableDiscoveryClient //启用添加服务注册中心
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class})
public class ResApplication extends SpringBootServletInitializer {
    public static void main( String[] args ){
        new SpringApplicationBuilder(ResApplication.class).web(WebApplicationType.SERVLET).run(args);
    }

    /**
     * 添加Xss漏洞过滤器
     * @return
     */
    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        //开启跨域过滤器
        filterRegistrationBean.setFilter(new CORSFilter());
        filterRegistrationBean.addUrlPatterns("*.woff","*.woff2","*.ttf","*.svg","*.eot","*.js","*.css","*.jpg","*.png");
        filterRegistrationBean.addInitParameter("cors.exposedHeaders","Set-Cookie");
        return filterRegistrationBean;
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(ResApplication.class);
    }
}
